#import <CoreSurface/CoreSurface.h>

#include <stdio.h>
#include <stdint.h>
#include <pthread.h>

extern  int     myargc;
extern  char**  myargv;

extern pthread_cond_t screenUpdateLock;
extern pthread_mutex_t screenUpdateMutex;
extern void updateScreen();
extern void D_DoomMain();
extern CoreSurfaceBufferRef screenSurface;

void iPhone_Video_End()
{
}

void iPhone_Video_LoadFrame(unsigned long *fb)
{
	unsigned short *c;
	int x, y, i = 0;

	c = CoreSurfaceBufferGetBaseAddress(screenSurface);

	pthread_mutex_lock(&screenUpdateMutex);

	for (y=0; y < 240; y++)
	{
		for (x=0; x<320; x++) {
			c[(320*y)+x] = fb[(320*y)+x];
		}
	}

	pthread_mutex_unlock(&screenUpdateMutex);
	updateScreen();
}

void iPhone_Video_Init()
{
}

void *game_thread(void *args) {
	myargc = 0;
	myargv = NULL;

	setenv("DOOMWADDIR", "/var/root/Media/Doom/", 1);
	D_DoomMain ();
}
